var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("GameEm"),
    s = t("MoveBaseCom"),
    c = cc._decorator,
    p = c.ccclass,
    l =
        (c.property,
        c.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.baseMoveSpeeds = 100;
                e.moveSpeeds = 100;
                e.foodData = null;
                e.pathIndexOff = 0;
                e.taskList = [];
                e.taskIndex = 0;
                e.kind = 0;
                e.id = 0;
                e.kindIndex = -1;
                e.checkEvent = !1;
                e.moveAren = "0";
                e.curMoveWayAren = "0";
                e.checkNextTask = 0;
                e.movePath = [];
                e.skinFront = {};
                e.equipSkin = {};
                e.moveCs = -1;
                e.pathIndex = 0;
                return e;
            }
            e.prototype.getKindIndex = function () {
                return this.kindIndex;
            };
            e.prototype.getId = function () {
                return this.id;
            };
            e.prototype.setBaseData = function (t, e, o, a, i) {
                this.moveAren = a;
                this.curMoveWayAren = "0";
                this.checkEvent = !0;
                this.kind = t;
                this.id = e;
                this.kindIndex = o;
                this.taskList = i;
                this.moveCs = -1;
                this.taskIndex = 0;
            };
            e.prototype.getFoodData = function () {
                return this.foodData;
            };
            e.prototype.setFoodData = function (t) {
                if (this.foodData) {
                    TaskLooper.putRoadCat(this.foodData);
                    this.foodData = null;
                }
                this.foodData = t;
                this.setMoveSpeeds(t.data.walk_speed);
            };
            e.prototype.setMoveSpeeds = function (t) {
                this.baseMoveSpeeds = t;
                this.updateSpeeds();
            };
            e.prototype.updateSpeeds = function () {
                this.moveSpeeds = this.baseMoveSpeeds;
                var t = 0;
                if (this.kind == r.catKind.npcCat) {
                    t += CacheDataManager.getAddAllAddtion(r.AddtionData.allMoveSpeedsAdd);
                    t += CacheDataManager.getAddCatAddtion(
                        this.id,
                        this.kindIndex + "",
                        r.AddtionData.allMoveSpeedsAdd
                    );
                    var e = (t += CacheDataManager.getOtherMoveSpeedAdd(this.kind, this.kindIndex + ""));
                    this.moveSpeeds = this.baseMoveSpeeds * e * CacheDataManager.debugMoveSpeeds;
                } else {
                    this.moveSpeeds += this.moveSpeeds * t;
                    var o = CacheDataManager.getLvUpgradeValueData(r.UpgradeData.roadCatMove);
                    this.moveSpeeds *= o;
                }
            };
            e.prototype.onLoad = function () {
                EvCat.on(EvCat.addCatTask, this.addTask.bind(this), this);
                EvCat.on(EvCat.readCatWantFood, this.updateFood.bind(this), this);
                EvCat.on(EvCat.callCat, this.callCat.bind(this), this);
                EvCat.on(EvCat.callKindCat, this.callKindNode.bind(this), this);
                EvCat.on(EvCat.callNextCS, this.callNextCs.bind(this), this);
                EvCat.on(EvCat.updateCatStatus, this.updateSpeeds.bind(this), this);
                EvCat.on(EvCat.updateCheckCs, this.updateCheckCs.bind(this), this);
                EvCat.on(EvCat.removeInvate, this.removeInvate.bind(this), this);
            };
            e.prototype.removeInvate = function () {};
            e.prototype.callNextCs = function (t, e, o) {
                this.moveCs == e && o && o(this);
            };
            e.prototype.callKindNode = function (t, e, o, a) {
                this.kind == e && this.kindIndex == o && a && a(this.node);
            };
            e.prototype.updateCheckCs = function () {};
            e.prototype.updateFood = function (t, e, o) {
                this.updateFoodStatus(e, o);
            };
            e.prototype.updateFoodStatus = function () {};
            e.prototype.checkTask = function () {};
            e.prototype.setPath = function (t) {
                if (this.movePath) {
                    this.updateSpeeds();
                    this.movePath.length = 0;
                    for (var e = 0; e < t.length; e++) this.movePath.push(t[e]);
                    this.movePath[this.pathIndex] ? (this.pathIndex = this.getMinPosIndex()) : (this.pathIndex = 0);
                }
            };
            e.prototype.getPathDisToIndex = function (t, e) {
                var o = 0;
                if (t && t.length > 0 && e > 0)
                    for (var a = t[t.length - 1], i = t.length - 2; i >= 0; i--) {
                        e -= a.sub(t[i]).mag();
                        a = t[i];
                        o = t.length - 2 - i;
                        if (e < 0) return o;
                    }
                return o;
            };
            e.prototype.startMoveNode = function (t, e) {
                this.pathIndex = Math.min(this.pathIndex, this.movePath.length - this.pathIndexOff);
                this.pathIndex = Math.max(this.pathIndex, 0);
                if (this.movePath && this.movePath[this.pathIndex]) {
                    var o = this.getMinPosIndex();
                    o >= 0 && o < this.movePath.length && (this.pathIndex = this.getMinPosIndex());
                    var a = this.movePath[this.pathIndex];
                    this.moveToPos(a, this.moveSpeeds, e);
                } else t && this.moveToPos(t, this.moveSpeeds, e, !0);
            };
            e.prototype.getMinPosIndex = function () {
                for (
                    var t = this.moveBaseNode().getPosition(),
                        e = this.getDisOfTwoPos(t, this.movePath[this.pathIndex]),
                        o = this.pathIndex,
                        a = this.moveSpeeds / 15,
                        i = this.pathIndex + 1;
                    i < this.movePath.length - this.pathIndexOff;
                    i++
                ) {
                    var n = this.getDisOfTwoPos(t, this.movePath[i]);
                    if (!(n < e || n < a)) break;
                    e = n;
                    o = i;
                }
                return o;
            };
            e.prototype.recNode = function () {
                QLooperNode.putNode(this.node);
            };
            e.prototype.clearData = function () {
                if (this.foodData) {
                    TaskLooper.putRoadCat(this.foodData);
                    this.foodData = null;
                }
                this.pathIndexOff = 0;
                this.id = -1;
                this.kind = -1;
                this.kindIndex = -1;
                this.moveAren = "0";
                this.checkNextTask = 0;
                this.recTaskList(this.taskList);
                this.taskList.length = 0;
                this.taskIndex = 0;
                this.checkEvent = !1;
                TaskGameEvent.offTarget(this);
                this.skinFront = {};
                this.equipSkin = {};
                this.stopMove();
            };
            e.prototype.getDisOfTwoPos = function (t, e) {
                return t.sub(e).mag();
            };
            e.prototype.addTask = function (t, e, o, a) {
                if (this.checkEvent && e == this.id) {
                    var i = this.taskIndex;
                    if (i > 0) {
                        this.recTaskList(this.taskList.splice(0, i));
                        this.taskIndex = 0;
                    }
                    this.taskList.push(o);
                    a && this.checkTask();
                }
            };
            e.prototype.recTaskList = function (t) {
                for (var e = 0; e < t.length; e++) TaskLooper.putTask(t[e]);
            };
            e.prototype.callCat = function (t, e, o) {
                this.checkEvent && e + "" == this.id + "" && o && o(e, this.node);
            };
            e.prototype.onDestroy = function () {
                EvCat.offTarget(this);
            };
            return n([p], e);
        })(s.default));
o.default = l;
